package com.love.marriage.datingRegistrationInfo.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.binarywang.wxpay.bean.result.WxPayUnifiedOrderV3Result;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSort;
import com.love.marriage.common.interfaces.avoid.AvoidRepeatableCommit;
import com.love.marriage.common.interfaces.avoid.LogRestRequest;
import com.love.marriage.common.validator.Update;
import com.love.marriage.common.vo.Result;
import com.love.marriage.common.vo.ResultBoolean;
import com.love.marriage.datingRegistrationInfo.service.DatingRegistrationInfoService;
import com.love.marriage.datingRegistrationInfo.vo.DatingRegistrationInfoVo;
import com.love.marriage.datingRegistrationInfo.vo.DatingSureRegistrationInfoVo;
import com.love.marriage.datingRegistrationInfo.vo.ResultDatingRegistrationInfoVo;
import com.love.marriage.datingRegistrationInfo.vo.ResultDatingRegistrationInfoVoPage;
import com.love.marriage.orderInfo.service.PayInfoService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;

/**
 * description:  约会报名表restApi
 * author:       mybatisPlus
 * createDate:   2024-10-15 23:02:33
 * version:      1.0.0
 */
@ApiSort(105)
@Tag(name = "约会报名表相关接口", description = "约会报名表相关接口")
@RestController
@RequiredArgsConstructor
@RequestMapping("/dating-registration-info")
public class DatingRegistrationInfoController {

    private final DatingRegistrationInfoService datingRegistrationInfoService;

    private final PayInfoService  payInfoService;

    @ApiOperationSupport(order = 10, author = "mybatisPlus")
    @Operation(summary = "获取约会报名表分页", description = "获取约会报名表分页")
    @ApiResponse(responseCode = "200", description = "Success",
            content = @Content(mediaType = "application/json",
                    schema = @Schema(implementation = ResultDatingRegistrationInfoVoPage.class
                    )))
    @PostMapping(value = "/page")
    @Parameters({
            @Parameter(name = "pageNum", description = "页码", required = false),
            @Parameter(name = "pageSize", description = "每页大小", required = false)
    })
    public Result<Page<DatingRegistrationInfoVo>> getPage(@RequestParam(value = "pageNum", required = false) Long pageNum,
                                                          @RequestParam(value = "pageSize", required = false) Long pageSize,
                                                          @RequestBody(required = false) DatingRegistrationInfoVo datingRegistrationInfoVo) {
        return Result.success(datingRegistrationInfoService.getPage(pageNum, pageSize, datingRegistrationInfoVo));
    }

    @ApiOperationSupport(order = 20, author = "mybatisPlus")
    @Operation(summary = "获取约会报名表详情", description = "获取约会报名表详情")
    @ApiResponse(responseCode = "200", description = "Success",
            content = @Content(mediaType = "application/json",
                    schema = @Schema(implementation = ResultDatingRegistrationInfoVo.class
                    )))
    @Parameters({
            @Parameter(name = "id", description = "id", required = true, schema = @Schema(implementation = Long.class, type = "Long", example = "1"))
    })
    @GetMapping
    public Result<DatingRegistrationInfoVo> query(@RequestParam(value = "id") Long id) {
        return Result.success(datingRegistrationInfoService.queryDatingRegistrationInfo(id));
    }

    @LogRestRequest(apiName = "应邀")
    @AvoidRepeatableCommit
    @ApiOperationSupport(order = 30, author = "mybatisPlus")
    @Operation(summary = "应邀", description = "应邀",
            requestBody = @io.swagger.v3.oas.annotations.parameters.RequestBody(
                    description = "查询条件",
                    required = false,
                    content = @Content(schema = @Schema(implementation = DatingRegistrationInfoVo.class))
            ))
    @ApiResponse(responseCode = "200", description = "Success",
            content = @Content(schema = @Schema(implementation = ResultDatingRegistrationInfoVo.class)))
    @PostMapping
    @Tag(name = "约会", description = "约会相关接口")
    public Result<DatingRegistrationInfoVo> add(@RequestBody DatingRegistrationInfoVo datingRegistrationInfoVo) throws Exception {
        return Result.success(datingRegistrationInfoService.addDatingRegistrationInfo(datingRegistrationInfoVo));
    }

    @AvoidRepeatableCommit
    @LogRestRequest(apiName = "应邀(微信支付)")
    @ApiOperationSupport(order = 35, author = "mybatisPlus")
    @Operation(summary = "应邀(微信支付)", description = "应邀(微信支付)",
            requestBody = @io.swagger.v3.oas.annotations.parameters.RequestBody(
                    description = "查询条件",
                    required = false,
                    content = @Content(schema = @Schema(implementation = DatingRegistrationInfoVo.class))
            ))
    @ApiResponse(responseCode = "200", description = "Success",
            content = @Content(schema = @Schema(implementation = ResultDatingRegistrationInfoVo.class)))
    @PostMapping(value = "dating_wechat")
    @Tag(name = "约会", description = "约会相关接口")
    public Result<WxPayUnifiedOrderV3Result.JsapiResult> addWechat(@RequestBody DatingRegistrationInfoVo datingRegistrationInfoVo) throws Exception {
        return Result.success(payInfoService.joinDatingWechat(datingRegistrationInfoVo));
    }

    @ApiOperationSupport(order = 40, author = "mybatisPlus")
    @Operation(summary = "修改约会报名表", description = "修改约会报名表",
            requestBody = @io.swagger.v3.oas.annotations.parameters.RequestBody(
                    description = "查询条件",
                    required = false,
                    content = @Content(schema = @Schema(implementation = DatingRegistrationInfoVo.class))
            ))
    @ApiResponse(responseCode = "200", description = "Success",
            content = @Content(schema = @Schema(implementation = ResultDatingRegistrationInfoVo.class)))
    @PutMapping
    public Result<DatingRegistrationInfoVo> update(@Validated({Update.class}) @RequestBody DatingRegistrationInfoVo datingRegistrationInfoVo) {
        return Result.success(datingRegistrationInfoService.updateDatingRegistrationInfo(datingRegistrationInfoVo));
    }

    @LogRestRequest(apiName = "发布者确认应邀")
    @ApiOperationSupport(order = 40, author = "mybatisPlus")
    @Operation(summary = "发布者确认应邀", description = "发布者确认应邀",
            requestBody = @io.swagger.v3.oas.annotations.parameters.RequestBody(
                    description = "查询条件",
                    required = false,
                    content = @Content(schema = @Schema(implementation = DatingSureRegistrationInfoVo.class))
            ))
    @ApiResponse(responseCode = "200", description = "Success",
            content = @Content(schema = @Schema(implementation = ResultDatingRegistrationInfoVo.class)))
    @PutMapping(value = "/sure-dating")
    public Result<DatingRegistrationInfoVo> sureDating(@Validated({Update.class}) @RequestBody DatingSureRegistrationInfoVo datingSureRegistrationInfoVo) {
        return Result.success(datingRegistrationInfoService.sureDating(datingSureRegistrationInfoVo));
    }

    @ApiOperationSupport(order = 50, author = "mybatisPlus")
    @Operation(summary = "刪除约会报名表", description = "刪除约会报名表")
    @Parameters({
            @Parameter(name = "ids", description = "ids,用，分割", required = true, schema = @Schema(implementation = String.class, type = "String", example = "1,2"))
    })
    @ApiResponse(responseCode = "200", description = "Success",
            content = @Content(schema = @Schema(implementation = ResultBoolean.class)))
    @DeleteMapping
    public Result<Boolean> delete(@RequestParam("ids") String ids) {
        return Result.success(datingRegistrationInfoService.deleteDatingRegistrationInfo(ids));
    }

    @ApiOperationSupport(order = 60, author = "mybatisPlus")
    @Operation(summary = "导出约会名单", description = "导出约会名单")
    @ApiResponse(responseCode = "200", description = "Success",
            content = @Content(mediaType = "application/json",
                    schema = @Schema(implementation = ResultBoolean.class
                    )))
    @PostMapping(value = "/export")
    public void export(@RequestBody(required = false) DatingRegistrationInfoVo datingRegistrationInfoVo, HttpServletResponse response) throws Exception {
        datingRegistrationInfoService.exportDatingRegistrationInfo(datingRegistrationInfoVo, response);
    }
}
